package com.weng.apistarter.utils;

import com.weng.framework.cache.redis.RedisClient;
import com.weng.sso.core.config.SsoConfig;
import com.weng.sso.core.model.SsoUser;

/*
 *  认证 信息存储  缓存
 * @author wengzhonghui
 * @date 11:58 2019/4/8
 */
public class TokenStore {

    private static int redisExpireMinite = SsoConfig.SSO_EXPIRE_TIME_LONG;    // 1440 minite, 24 hour


    public static SsoUser get(String storeKey) {

        String redisKey = redisKey(storeKey);
        return RedisClient.get(redisKey, SsoUser.class);
    }

    /**
     * remove
     * @param storeKey
     */
    public static void remove(String storeKey) {
        String redisKey = redisKey(storeKey);
        RedisClient.delete(redisKey);
    }

    public static void put(String storeKey, SsoUser ssoUser) {
        String redisKey = redisKey(storeKey);
        RedisClient.set(redisKey,ssoUser,redisExpireMinite);
    }

    private static String redisKey(String sessionId){
        return SsoConfig.SSO_SESSIONID.concat("#").concat(sessionId);
    }

}
